﻿using Microsoft.ApplicationBlocks.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;

namespace ERB.App_Code.BAL.CRM
{

    public class SupplierClass
    {
        #region Properties
        public int SupplierID { set; get; }
        public int BankID { set; get; }
        public int TermID { set; get; }
        public int SupplierGroupID { set; get; }
        public string SupplierContact { set; get; }
        public string SupplierCode { set; get; }
        public string SupplierName { set; get; }
        public string Address { set; get; }
        public string Phone { set; get; }
        public string Email { set; get; }
        public string Mobile { set; get; }
        public string Website { set; get; }
        public string Fax { set; get; }
        public string TaxCode { set; get; }
        public string BankAccount { set; get; }
        public string ImageURL { set; get; }
        public string BOID { set; get; }
        public string UserCreate { set; get; }
        public DateTime CreateDate { set; get; }
        public string UserUpdate { set; get; }
        public DateTime UpdateDate { set; get; }
        public string IsDeleted { set; get; }
        #endregion

        public SupplierClass() { }

        public static Boolean Insert(SupplierClass sup)
        {
            int rs = 0;
            try
            {
                rs = SqlHelper.ExecuteNonQuery(DataServices.ConnectString, "sp_Supplier_Insert",
                                                    sup.BankID,
                                                    sup.SupplierGroupID,
                                                    sup.TermID,
                                                    sup.SupplierCode,
                                                    sup.SupplierName,
                                                    sup.SupplierContact,
                                                    sup.Address,
                                                    sup.Phone,
                                                    sup.Mobile,
                                                    sup.Email,
                                                    sup.Website,
                                                    sup.Fax,
                                                    sup.TaxCode,
                                                    sup.BankAccount,
                                                    sup.ImageURL,
                                                    sup.BOID,
                                                    sup.UserCreate);
            }
            catch { }
            bool isSuccess = false;
            if (rs > 0)
                isSuccess = true;
            return isSuccess;
        }

        public static Boolean Update(SupplierClass sup)
        {
            int rs = 0;
            try
            {
                rs = SqlHelper.ExecuteNonQuery(DataServices.ConnectString, "sp_Supplier_Update",
                                                sup.SupplierID,
                                                sup.BankID,
                                                sup.SupplierGroupID,
                                                sup.TermID,
                                                sup.SupplierCode,
                                                sup.SupplierName,
                                                sup.SupplierContact,
                                                sup.Address,
                                                sup.Phone,
                                                sup.Mobile,
                                                sup.Website,
                                                sup.Email,
                                                sup.Fax,
                                                sup.TaxCode,
                                                sup.BankAccount,
                                                sup.ImageURL,
                                                sup.BOID,
                                                sup.UserUpdate);
            }
            catch { }
            bool isSuccess = false;
            if (rs > 0)
                isSuccess = true;
            return isSuccess;
        }

        public static DataTable SelectAll(SupplierClass sup)
        {
            DataTable dt = new DataTable();
            try
            {
                dt = SqlHelper.ExecuteDataset(DataServices.ConnectString, "sp_Supplier_SelectAll", sup.BOID).Tables[0];
            }
            catch { }
            return dt;
        }

        public static DataTable SelectByID(SupplierClass sup)
        {
            DataTable dt = new DataTable();
            try
            {
                return SqlHelper.ExecuteDataset(DataServices.ConnectString, "sp_Supplier_SelectByID", sup.SupplierID, sup.BOID).Tables[0];
            }
            catch { }
            return dt;
        }

        public static DataTable SelectByName(SupplierClass sup)
        {
            DataTable dt = new DataTable();
            try
            {
                dt = SqlHelper.ExecuteDataset(DataServices.ConnectString, "sp_Supplier_SelectByName", sup.SupplierName, sup.BOID).Tables[0];
            }
            catch { }
            return dt;
        }

        public static Boolean Delete(SupplierClass sup)
        {
            int rs = 0;
            try
            {
                rs = SqlHelper.ExecuteNonQuery(DataServices.ConnectString, "sp_Supplier_Delete", sup.SupplierID, sup.BOID);
            }
            catch { }
            bool isSuccess = false;
            if (rs > 0)
                isSuccess = true;
            return isSuccess;
        }
    }
}